package pe.gob.mpfn.model;

import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PersistenceContext;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.dbre.RooDbManaged;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;
import org.springframework.transaction.annotation.Transactional;

@Entity
@Table(name = "detalle_diligencia")
@Configurable
@RooJavaBean
@RooToString
@RooJpaActiveRecord(versionField = "", table = "detalle_diligencia")
@RooDbManaged(automaticallyDelete = true)
public class DetalleDiligencia {

	@PersistenceContext
    transient EntityManager entityManager;

	public static final EntityManager entityManager() {
        EntityManager em = new DetalleDiligencia().entityManager;
        if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
        return em;
    }

	public static long countDetalleDiligencias() {
        return entityManager().createQuery("SELECT COUNT(o) FROM DetalleDiligencia o", Long.class).getSingleResult();
    }

	public static List<DetalleDiligencia> findAllDetalleDiligencias() {
        return entityManager().createQuery("SELECT o FROM DetalleDiligencia o", DetalleDiligencia.class).getResultList();
    }

	public static DetalleDiligencia findDetalleDiligencia(Integer intDetalleDiligenciaId) {
        if (intDetalleDiligenciaId == null) return null;
        return entityManager().find(DetalleDiligencia.class, intDetalleDiligenciaId);
    }

	public static List<DetalleDiligencia> findDetalleDiligenciaEntries(int firstResult, int maxResults) {
        return entityManager().createQuery("SELECT o FROM DetalleDiligencia o", DetalleDiligencia.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
    }

	@Transactional
    public void persist() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.persist(this);
    }

	@Transactional
    public void remove() {
        if (this.entityManager == null) this.entityManager = entityManager();
        if (this.entityManager.contains(this)) {
            this.entityManager.remove(this);
        } else {
            DetalleDiligencia attached = DetalleDiligencia.findDetalleDiligencia(this.intDetalleDiligenciaId);
            this.entityManager.remove(attached);
        }
    }

	@Transactional
    public void flush() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.flush();
    }

	@Transactional
    public void clear() {
        if (this.entityManager == null) this.entityManager = entityManager();
        this.entityManager.clear();
    }

	@Transactional
    public DetalleDiligencia merge() {
        if (this.entityManager == null) this.entityManager = entityManager();
        DetalleDiligencia merged = this.entityManager.merge(this);
        this.entityManager.flush();
        return merged;
    }

	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	@ManyToOne
    @JoinColumn(name = "int_diligencia_id", referencedColumnName = "int_diligencia_id", nullable = false)
    private Diligencia intDiligenciaId;

	@Column(name = "str_descripcion", columnDefinition = "VARCHAR", length = 200)
    @NotNull
    private String strDescripcion;

	@Column(name = "str_responsable", columnDefinition = "VARCHAR", length = 200)
    @NotNull
    private String strResponsable;

	@Column(name = "dat_fecha_registro", columnDefinition = "DATETIME")
    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Date datFechaRegistro;

	@Column(name = "txt_imagen", columnDefinition = "TEXT")
    @NotNull
    private String txtImagen;

	@Column(name = "chr_estado", columnDefinition = "CHAR")
    @NotNull
    private Character chrEstado;

	public Diligencia getIntDiligenciaId() {
        return intDiligenciaId;
    }

	public void setIntDiligenciaId(Diligencia intDiligenciaId) {
        this.intDiligenciaId = intDiligenciaId;
    }

	public String getStrDescripcion() {
        return strDescripcion;
    }

	public void setStrDescripcion(String strDescripcion) {
        this.strDescripcion = strDescripcion;
    }

	public String getStrResponsable() {
        return strResponsable;
    }

	public void setStrResponsable(String strResponsable) {
        this.strResponsable = strResponsable;
    }

	public Date getDatFechaRegistro() {
        return datFechaRegistro;
    }

	public void setDatFechaRegistro(Date datFechaRegistro) {
        this.datFechaRegistro = datFechaRegistro;
    }

	public String getTxtImagen() {
        return txtImagen;
    }

	public void setTxtImagen(String txtImagen) {
        this.txtImagen = txtImagen;
    }

	public Character getChrEstado() {
        return chrEstado;
    }

	public void setChrEstado(Character chrEstado) {
        this.chrEstado = chrEstado;
    }

	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "int_detalle_diligencia_id", columnDefinition = "INT")
    private Integer intDetalleDiligenciaId;

	public Integer getIntDetalleDiligenciaId() {
        return this.intDetalleDiligenciaId;
    }

	public void setIntDetalleDiligenciaId(Integer id) {
        this.intDetalleDiligenciaId = id;
    }
}
